package com.supreme.threadserver.threadpkg;

import com.supreme.threadserver.utils.StupidUtils;

import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

public class SupplierTask implements Supplier<String> {

    private final String nickname;
    private long timeout = 0L;

    public SupplierTask(String nickname) {
        this.nickname = nickname;
    }

    public SupplierTask setTimeout(Long timeout) {
        this.timeout = timeout;
        return this;
    }

    @Override
    public String get() {
        StupidUtils.showThreadName(String.format("SupplierTask: %s", this.nickname));
        try {
            TimeUnit.MILLISECONDS.sleep(this.timeout);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return this.nickname;
    }
}
